

/***********************************************************
 *     momodel.c
 *
 *     该文件由MWorks.Sysplorer嵌入式代码生成器自动生成。
 *
 *     模型名称：SECModel5_iic
 *     生成时间：2023-11-14 10:39:10
 *
 *     苏州同元软控信息技术有限公司
 *              2005-2023
 *
 ***********************************************************/

#include "string.h"

#include "math.h"

#include "momodel.h"

#include "momodel_extern_inc.h"

#define SECMODEL5_IIC_MW_R_SIZE 1

#define SECMODEL5_IIC_INTE_STEP_SIZE 0.002

#define _TIME model_data._Time

#define SECMODEL5_IIC_MW_R model_data.m_real

#define SECMODEL5_IIC_MAX_INT32_T ((MoInt32)(2147483647))

#define SECMODEL5_IIC_MIN_INT32_T ((MoInt32)(-2147483647 - 1))

#define Secmodel5_iicIsModelInit() model_data.m_modelInit

#define Secmodel5_iicSetModelInit(val) model_data.m_modelInit = (val)

#define Secmodel5_iicIsModelInitialed() model_data.m_modelInitEnd

#define Secmodel5_iicSetModelInitialed(val) model_data.m_modelInitEnd = (val)

#define Secmodel5_iicGetTime() _TIME

#define Secmodel5_iicSetTime(val) _TIME = (val)

#define Secmodel5_iicGetStepSizeM() model_data.m_stepSize

#define Secmodel5_iicGetStepCount() model_data.m_stepCount

#define Secmodel5_iicIncStepCount() ++model_data.m_stepCount

#define Secmodel5_iicGetStartTime() model_data.m_startTime

#define Secmodel5_iicSetStartTime(val) model_data.m_startTime = (val)

struct Secmodel5_iicSolverModelData
{
  MoDouble m_stepSize;
  MoSize m_stepCount;
  MoDouble m_startTime;
  MoDouble _Time;
  Secmodel5_iicSecmodel5u_iic m_vars;

  MoBool m_modelInit;
  MoBool m_modelInitEnd;
};

MoInt readaddr;

MoInt outdata;

MoInt readflag;

MoInt writeaddr;

MoInt writeData;

MoInt writeflag;

struct Secmodel5_iicSolverModelData model_data;

enum MW_STATUS Secmodel5_iicDoPreUpdate(void);

void AT24CXX_Init();

void AT24CXX_WriteOneByte_user(MoInt, MoInt, MoInt);

MoInt AT24CXX_ReadOneByte_user(MoInt, MoInt);

void SECModel5u_iica_at24cxxu_init11();

void SECModel5u_iica_at24cxxu_write2(MoInt WriteAddr, MoInt DataToWrite, MoInt flag_write);

MoInt SECModel5u_iica_at24cxxu_reado3(MoInt ReadAddr, MoInt flag_read);

void Secmodel5_iicSampleDataInit(void);

enum MW_STATUS Secmodel5_iicDoModelVarInit(void)
{

  readaddr = 0;

  outdata = 0;

  readflag = 0;

  writeaddr = 0;

  writeData = 0;

  writeflag = 0;

  /* Inital sample data*/
  Secmodel5_iicSampleDataInit();
  /* Depending parameter values */

  /* Fixed equations */
  SECModel5u_iica_at24cxxu_init11();

  /* Initial equations */

  (void)Secmodel5_iicDoPreUpdate();

  return MW_STATUS_OK;
} /*Secmodel5_iicDoModelVarInit*/

enum MW_STATUS Secmodel5_iicDoPreUpdate(void)
{ /* No pre variables, do nothing */
  return MW_STATUS_OK;
}

enum MW_STATUS SECModel5_iic_DoStep(void)
{
  if (!Secmodel5_iicIsModelInit() && !Secmodel5_iicIsModelInitialed())
  {
    Secmodel5_iicIncStepCount();
  }
  Secmodel5_iicSetTime(Secmodel5_iicGetStartTime() +
                       Secmodel5_iicGetStepCount() * SECMODEL5_IIC_INTE_STEP_SIZE);

  /*if (Secmodel5_iicIsIntegeratorStep())*/
  {
    SECModel5u_iica_at24cxxu_init11();

    /* Normal equations */
    SECModel5u_iica_at24cxxu_write2(writeaddr, writeData, writeflag);

    outdata = SECModel5u_iica_at24cxxu_reado3(readaddr, readflag);

    /* Reinit equations */
    /* Update pre variable */
    (void)Secmodel5_iicDoPreUpdate();
    /* Update when condition */

    /* Check variable value */
  }

  return MW_STATUS_OK;
} /*Secmodel5_iicDoModelCalculate*/

/* SECModel5_iic.at24cxx_init1.func_CCaller1 */

void SECModel5u_iica_at24cxxu_init11(void) { AT24CXX_Init(); }

/* SECModel5_iic.at24cxx_writeonebyte_user1.func_CCaller1 */

void SECModel5u_iica_at24cxxu_write2(MoInt WriteAddr, MoInt DataToWrite, MoInt flag_write)
{

  AT24CXX_WriteOneByte_user(WriteAddr, DataToWrite, flag_write);
}

/* SECModel5_iic.at24cxx_readonebyte_user1.func_CCaller1 */

MoInt SECModel5u_iica_at24cxxu_reado3(MoInt ReadAddr, MoInt flag_read)
{

  MoInt out;

  out = 0;

  out = AT24CXX_ReadOneByte_user(ReadAddr, flag_read);

  return out;
}

MoDouble Secmodel5_iicGetStepSize(void) { return model_data.m_stepSize; }

void Secmodel5_iicSetStepSize(MoDouble val) { model_data.m_stepSize = val; }

enum MW_STATUS SECModel5_iic_Init(void)
{
  enum MW_STATUS stat;

  (void)memset(&model_data, 0, sizeof(struct Secmodel5_iicSolverModelData));
  Secmodel5_iicSetStepSize(SECMODEL5_IIC_INTE_STEP_SIZE);
  Secmodel5_iicDoModelVarInit();

  Secmodel5_iicSetStepSize(0.0);
  Secmodel5_iicSetModelInit(moTrue);
  Secmodel5_iicSetTime(0);
  Secmodel5_iicSetStartTime(0);
  stat = SECModel5_iic_DoStep();
  if (MW_STATUS_OK == stat)
  {
    Secmodel5_iicSetModelInit(moFalse);
    Secmodel5_iicSetModelInitialed(moTrue);
    stat = SECModel5_iic_DoStep();
    if (MW_STATUS_OK == stat)
    {
      Secmodel5_iicSetStepSize(SECMODEL5_IIC_INTE_STEP_SIZE);
      Secmodel5_iicSetModelInitialed(moFalse);
    }
  }

  return stat;
}

MoDouble Secmodel5_iicGetCurTime(void) { return Secmodel5_iicGetTime(); }

void Secmodel5_iicSampleDataInit(void) {}
